package com.jf.mall.dao.impl;

import com.jf.mall.dao.BasicDAO;
import com.jf.mall.dao.OrderItemDAO;
import com.jf.mall.domain.OrderItem;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-10-10
 * Time:20:45
 */
public class OrderItemImpl extends BasicDAO<OrderItem> implements OrderItemDAO {
    @Override
    public int insertOrderItem(OrderItem orderItem) {
        String sql = "insert into order_item(order_id, `name`, unit_price, `count`, total_price) values(?, ?, ?, ?, ?)";
        String orderId = orderItem.getOrderId();
        String name = orderItem.getName();
        BigDecimal unitPrice = orderItem.getUnitPrice();
        Integer count = orderItem.getCount();
        BigDecimal totalPrice = orderItem.getTotalPrice();
        try {
            return update(sql, orderId, name, unitPrice, count, totalPrice);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<OrderItem> getOrderItemsByOrderId(String orderId) {
        String sql = "select id, order_id orderId, `name`, unit_price unitPrice, `count`, total_price totalPrice from order_item where order_id = ?";
        return queryMulti(sql, OrderItem.class, orderId);
    }
}
